feat(rag): Ask this book — on-demand indexing P2 (user-uploaded books)#384
Merged
Conversation
Extends Ask to user-uploaded books (the priority — users read their own uploads).
Per-user ISOLATION is a hard requirement.
- New ISOLATED user_chapter_chunk table (NOT polymorphic), denormalized user_id +
user_book_id; retrieval filters BOTH in every SQL branch (vector + lexical).
- UserBook gains rag_* fields; BookChunkingService.ChunkUserBookAsync; worker
second poll over user_chapter_chunk on the SAME OpenAI drain, flips Ready.
- IRagService.RetrieveUserBookAsync (shared RRF helper, byte-identical fusion).
- UserBookRagContextService: NO spoiler gate (your own doc -> full-book retrieval).
- Owner-scoped POST/GET /me/books/{id}/index + POST /me/books/{id}/ask (404 non-owner).
Atomic claim WHERE user_id=@uid; clears chunks (filtered by user_id too) before
re-chunk; rate-limited.
- GET /me/books/{id} detail gains ragStatus/counts.
- Web: askTarget abstraction unhides Ask for mode=userbook -> /me/books/{id}/...;
catalog path unchanged.
- Migration AddUserBookRagIndex (user_chapter_chunk + HNSW/GIN/(user_id,user_book_id)
+ cascade FKs from user_books AND user_chapters).
architect -> backend+frontend -> adversarial QA on ISOLATION (verdict SHIP; both
SQL branches filter user_id+user_book_id, owner-404, FK-cascade purge, no cross-
corpus; P3 DELETE owner-scope applied). 855 unit + 559 web green; build clean.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Extends "Ask this book" to user-uploaded books — the priority (users read their own uploads; the button was previously hidden for
mode==='userbook').Per-user isolation is a hard requirement and was the QA focus:
user_chapter_chunktable (NOT polymorphic with catalogchapter_chunk), denormalizeduser_id+user_book_id; every retrieval SQL branch (vector NN + lexical FTS) filters on both. Owner-scoped endpoints 404 for a foreign id (no existence leak). FK cascade purges chunks when a book is deleted.UserBookgainsrag_*fields;BookChunkingService.ChunkUserBookAsync;ChapterEmbeddingWorkersecond poll on the same OpenAI drain;IRagService.RetrieveUserBookAsync(shared RRF helper). No spoiler gate for user books (full-book retrieval over your own doc).POST/GET /me/books/{id}/index+POST /me/books/{id}/ask;GET /me/books/{id}detail gainsragStatus/counts. MigrationAddUserBookRagIndex.askTargetabstraction routes userbook →/me/books/{id}/...; catalog path unchanged.architect → backend + frontend → adversarial QA on isolation (verdict SHIP) — both SQL branches scope to the owner, no cross-corpus union, P3 DELETE owner-scope applied. 855 unit + 559 web tests green; solution + web build clean.
🤖 Generated with Claude Code